package com.itqf.Controller;

import com.github.pagehelper.PageInfo;
import com.itqf.Service.Applystage.ApplystageService;
import com.itqf.Service.Topic.TopicService;
import com.itqf.Util.myPageInfo;
import com.itqf.entity.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class TopicController {

    @Resource
    private TopicService topicService;
    @Resource
    private ApplystageService applystageService;
    //首页显示的所有数据
    @RequestMapping(value = "/homePage",method = RequestMethod.GET)
    @ResponseBody
    public Topicjson getTopicjson(@RequestParam(defaultValue = "-1") int subjectId,@RequestParam(defaultValue = "-1") int gradeid)
    {
        //1.根据年级查询每个年级所有的科目的
        List<Subject> findsubjects = topicService.findsubjects(gradeid);
        //2.通过科目显示精品推荐的商品
        List<Topic> topicList=topicService.findtopic(subjectId);
        Topicjson topicjson=new Topicjson();
        topicjson.setSubjectsList(findsubjects);
        topicjson.setTopicList(topicList);
        //3.查找所有年级用于下拉框选择年级
        List<Applystage> applystages=applystageService.findallgrades();
        topicjson.setApplystages(applystages);

        return topicjson;
    }
    //首页搜索框的内容,其他页搜索框也可以调用该接口
    @RequestMapping(value = "/search",method = RequestMethod.POST)
    @ResponseBody
    public PageInfo gettopicslist(String searchname,@RequestParam(defaultValue = "1") int pageindex)
    {
       PageInfo<Topic>  pageInfo=topicService.findbysearchname(pageindex, myPageInfo.PAGESIZE,searchname);
       return pageInfo;
    }



}
